function makeHash(path: string): string {
	let hash = window.location.hash;
	if (hash.startsWith('#')) {
		hash = hash.substring(1);
	}
	if (hash.endsWith('/')) {
		hash = hash.substring(0, hash.length - 1);
	}
	if (!path.startsWith('/')) {
		path = hash + '/' + path;
	}
	if (path.endsWith('/')) {
		path = path.substring(0, path.length - 1);
	}
	if (path) {
		return '#' + path;
	} else {
		return '';
	}
}

export const Router = {
	push(path: string) {
		window.location.assign(makeHash(path));
	},
	pop(num?: number) {
		if (typeof num === 'number' && num > 1) {
			window.history.go(-num);
		} else {
			window.history.back();
		}
	},
	replace(path: string) {
		window.location.replace(makeHash(path));
	},
};
